package cn.edu.zut.sunday.news.func;

import cn.edu.zut.sunday.news.domain.News;
import cn.edu.zut.sunday.news.vo.NewsVo;
import com.google.gson.Gson;
import java.util.function.Function;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@UtilityClass
public class NewsCategoryTransformUtils {

    public static final Function<News, NewsVo> ENTITY_2_VO = news -> {
        log.info("news: {}", news);
        final NewsVo newsVo = new NewsVo();
        newsVo.setTitle(news.getTitle());
        newsVo.setSource(news.getSource());
        newsVo.setHeadImgUrl(news.getHeadImgUrl());
        newsVo.setPublishTime(news.getPublishTime());
        newsVo.setUrl(news.getUrl());
        newsVo.setNewsCategory(news.getNewsCategory());
        newsVo.setKeyword(news.getKeyword());
        newsVo.setTag(news.getTag());
        newsVo.setDescription(news.getDescription());
        newsVo.setContent(news.getContent());
        newsVo.setDateCreated(news.getDateCreated());
        newsVo.setDateModified(news.getDateModified());
        newsVo.setId(news.getId());

        // 从newsCategory属性中读取category属性
        newsVo.setCategory(news.getNewsCategory().getCategory());
        return newsVo;
    };

}
